package org.icy.core.setup.verification;

import java.util.ArrayList;

import org.icy.core.setup.VerificationResult;
import org.icy.utils.ClassLoaderUtils;

public class DatabaseVerification implements Verification {
	
	private String[] supported = new String[] {"com.mysql.jdbc.Driver"};
	private String[] supportedNames = new String[] {"MySQL"};
	private String[] supportedAdapter = new String[] {"org.ice.db.MySqlAdapter"};

	@Override
	public VerificationResult verify() {
		for(String s: supported) {
			if (ClassLoaderUtils.testClass(s)) {
				return new VerificationResult(true, "Yes", "Database support", null);
			}
		}
		return new VerificationResult(false, "No", "Database support", "No supported drivers present.");
	}

	public ArrayList<VerificationResult> getSupportedDatabases() {
		ArrayList<VerificationResult> result = new ArrayList<VerificationResult>();
		for(int i=0;i<supported.length;i++) {
			if (ClassLoaderUtils.testClass(supported[i])) {
				result.add(new VerificationResult(true, supportedNames[i], null, null));
			}
		}
		return result;
	}

	public String getSupportedAdapter(String db) {
		for(int i=0;i<supportedNames.length;i++) {
			if (supportedNames[i].equals(db)) {
				return supportedAdapter[i];
			}
		}
		return null;
	}
}
